package com.qf.commons.web.exception.handler;

import com.qf.commons.standar.exception.IExceptionHandler;
import com.qf.data.base.r.Codes;
import com.qf.data.base.r.R;
import com.qf.data.base.r.Rs;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Component;

/**
 * description:
 * author: Ken
 * 公众号：Java架构栈
 */
@Component
public class SQLDataInsertExceptionHandler implements IExceptionHandler {

    @Override
    public boolean isSupport(Exception e) {
        return e.getClass() == DuplicateKeyException.class;
    }

    @Override
    public R exceptionHandler(Exception e) {
        return Rs.createFail(Codes.DATA_REPE);
    }
}
